package com.ke.jdyd.service;

import com.ke.jdyd.http.BaseResponse;
import com.ke.jdyd.http.HttpParamHelper;
import com.ke.jdyd.http.RetrofitFactory;

import java.util.HashMap;
import java.util.Map;

import io.reactivex.Observable;
import okhttp3.RequestBody;
import retrofit2.http.Multipart;
import retrofit2.http.POST;
import retrofit2.http.PartMap;

public class LoginService {
  private LoginApi mApi;
  public LoginService() {
    mApi = RetrofitFactory.getInstance().getApi(LoginApi.class);
  }

  /**
   *
   * @param name
   * @param pws
   * @return 网络请求 结果返回
   */
  public Observable<BaseResponse<UserInfo>> loginIn(String name, String pws) {
    //处理网络请求
    Map<String, String> map = new HashMap<>();
    map.put("username", name);
    map.put("password", pws);
   return mApi.loginIn(HttpParamHelper.generateRequestBody(map));

  }

  interface LoginApi {
    @Multipart
    @POST("/api/apiuser/login")//服务端请求数据 base_url + url  == 完整的请求地址
    Observable<BaseResponse<UserInfo>> loginIn(@PartMap Map<String, RequestBody> requestBodyMap);
  }
  public class UserInfo {
    private String token;

    public String getToken() {
      return token;
    }

    public void setToken(String token) {
      this.token = token;
    }
  }

}
